<template>
  <div class="video">
    <div :id="this.id"></div>
  </div>
</template>

<script>
import EZUIKit from 'ezuikit-js'

let player = null
let appKey = process.env.VUE_APP_KEY
let appSecret = process.env.VUE_APP_SECRET
let options = {
  method: 'POST',//post请求
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'appKey='+appKey+'&appSecret='+appSecret,
}
let accessToken;
export default {
  name: 'Video',
  props: {
    msg: String,
    id: String,
    channelNo: Number,
    deviceSerial: String,
    width: {
      type: Number,
      default: 600
    },
    height: {
      type: Number,
      default: 400
    }
  },
  mounted() {
    this.getVideo(this.id, this.channelNo, this.deviceSerial)
  },
  beforeDestroy() {
    if (this.player)this.player.stop();
  },
  methods: {
    getVideo(id, channelNo, deviceSerial) {
      player = new EZUIKit.EZUIKitPlayer({
        id: id, // 视频容器ID
        accessToken: this.$store.getters.videoToken,
        url: 'ezopen://open.ys7.com/' + deviceSerial + '/' + channelNo + '.live',
        // simple - 极简版; pcLive-pc直播；pcRec-pc回放；mobileLive-移动端直播；mobileRec-移动端回放;security - 安防版;voice-语音版;
        template: 'pcLive',
        // plugin: ['talk'], // 加载插件，talk-对讲
        audio: 0,
        autoplay: false,
        width: this.width,
        height: this.height
      })
      // window.player = player
    },
  }
}
</script>
